/*
 * TestWindow.java
 *
 * Created on 15.okt.2011, 23:01:40
 */
package GUInemeanshop;

import java.awt.Color;
import javax.swing.JOptionPane;
import nemeanshop.Database;
import nemeanshop.NemeanShop;
import nemeanshop.Product;

/**
 *
 * @author Ragnar
 */
public class TestWindow extends javax.swing.JFrame
{
    private Database db;
    private NemeanShop ns;
    private Color c             = new Color(0,0,0, 100);
    private Color t             = new Color(255,255,255, 0);

    /** Creates new form TestWindow */
    public TestWindow()
    {
                
        try
        {
            this.db = new Database();
            System.out.println(ns.getAllProducts());
            System.out.println(ns.getAllProducts());
            db.getAllProducts();
        }
        catch(Exception e)
        {
            
        }
        initComponents();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Nemean Shop");
        setMinimumSize(new java.awt.Dimension(200, 200));

        jButton1.setText("Add Product");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Get Product");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(93, 93, 93)
                .addComponent(jButton1)
                .addGap(29, 29, 29)
                .addComponent(jButton2)
                .addContainerGap(98, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(221, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        AddProduct2 ap = new AddProduct2(this, true);
        if (ap.getState() == Status.OK)
        {
            try
            {
                if (db.addProduct(ap.getBarcode(), ap.getProductName(), ap.getStockPrice(), ap.getSellPrice(), ap.getQuantity()))
                {
                    JOptionPane.showMessageDialog(null, "Produkt lagt til!");
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "Kunne ikke legge til produkt!");
                }
            }
            catch (Exception e)
            {
                JOptionPane.showMessageDialog(null, e.getMessage());
            }
            System.out.println(ap.getStockPrice());
        }
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
        try
        {
            Product p = this.db.getProduct("asdjklf");
            System.out.println(p.getProductName());
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {

            public void run()
            {
                new TestWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    // End of variables declaration//GEN-END:variables
}
